package edu.ust.seis610;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.BasicConfigurator;
import twitter4j.TwitterException;
import edu.ust.seis610.data.DataPoint;
import edu.ust.seis610.data.PropertyManager;
import edu.ust.seis610.data.TrainingData;
import edu.ust.seis610.function.Function;
import edu.ust.seis610.twitter.Tweet;
import edu.ust.seis610.utils.DateUtils;

import edu.ust.seis610.chart.DynamicChart;
import org.jfree.ui.RefineryUtilities;

/**
 * @author meeusen
 *
 */
public class GeneticPRG
{
	private static Log log=LogFactory.getLog(GeneticPRG.class);
	/**
	 * @param args
	 */
	@SuppressWarnings("unused")
	public static void main(String[] args)
	{
		GeneticPRG prg = new GeneticPRG();
	}

	public GeneticPRG()
	{
		doSetupAndBeginRun();
	}

	@SuppressWarnings("unused")
	private void doSetupAndBeginRun()
	{
		try
		{
			BasicConfigurator.configure();
			loadSystemProperties();
	        DynamicChart chart = new DynamicChart("GA Program");
	        chart.pack();
	        RefineryUtilities.centerFrameOnScreen(chart);
	        chart.setVisible(true);
			FunctionRunner fr = new FunctionRunner();
			Function bestFunction = fr.findTargetFunction(Boolean.parseBoolean(PropertyManager.getProperty("tweet.out.results")),
					Boolean.parseBoolean(PropertyManager.getProperty("create.training.data")),Integer.parseInt(PropertyManager.getProperty("init.population.size")),
					Double.parseDouble(PropertyManager.getProperty("mutation.percentage")), Double.parseDouble(PropertyManager.getProperty("crossover.percentage")),
					chart,15);
		}
		catch(Exception ex)
		{
			log.error(ex.getMessage(), ex);
		}
	}

	@SuppressWarnings("unused")
	private void printSysetemProperties()
	{
//    	display all system properties in console
    	System.getProperties().list(System.out);
	}

	private void loadSystemProperties()
	{
		try
	    {
//			 set up new properties object
//	    	 from file "defaultProperties.properties"
	        FileInputStream propFile = new FileInputStream("configuration.properties");
	        Properties p = new Properties(System.getProperties());
	        p.load(propFile);

//	         set the system properties
	        System.setProperties(p);
	    }
	    catch(Exception ex)
	    {
	       	System.out.println(ex.getMessage());
	    }	
	}	
}
